<template>
  <div class="login-page">
    <!--        修改的头部-->
    <div class="login-top">
      <div class="logoBox"><img src="/img/bg/logo.jpg" /></div>
      <p>AI智慧校园</p>
    </div>
    <!--        修改的登录部分-->
    <div class="login-container">
      <div class="login-weaper">
        <div class="login-bg"><img src="/img/bg/login.jpg" /><img /></div>
        <div class="floatRight animated bounceInDown">
          <div class="login-menu">
            <p class="normal">
              <a href="#" @click.stop="activeName = 'user'" v-show="true"
                >密码登录</a
              >
            </p>
            <!--            <p>-->
            <!--              <a href="#"-->
            <!--                 @click.stop="activeName='third'">扫码登录</a>-->
            <!--            </p>-->
          </div>
          <!-- <div class="login-logo">
            < img src="/img/logo.png" alt="">
          </div> -->
          <!-- <p class="login-tip">{{ website.title}} v 3.11</p > -->
          <div class="login-border">
            <div class="login-main">
              <!-- <h4 class="login-title">
                <el-select v-model="active"
                           class="login-select animated fadeIn"
                           placeholder="点击请选择租户"
                           @change="handleCommand">
                  <el-option v-for="tenant in tenantList"
                             :key="tenant.id"
                             :label="tenant.name"
                             :value="tenant.id"></el-option>
                </el-select>
              </h4> -->
              <userLogin v-if="activeName === 'user'" />
              <!-- <codeLogin v-else-if="activeName==='code'" /> -->
              <!--              <thirdLogin v-else-if="activeName==='third'" />-->
            </div>
          </div>
          <!--          <p class="login-tip">无法登录？<a href="#">点击反馈</a></p >-->
        </div>
      </div>
      <top-color v-show="false" />
    </div>
    <!--        修改的脚部-->
    <div class="login-footer">
      <div class="login-sbox">
        <ul>
          <li>
            <a href="#">联系客服</a>
          </li>
          <li>|</li>
          <li>
            <a href="#">加入我们</a>
          </li>
          <li>|</li>
          <li>
            <a href="#">关于我们</a>
          </li>
          <li>|</li>
          <li>
            <a href="#">友情链接</a>
          </li>
        </ul>
      </div>
      <div class="login-copyright">
        {{ website.copyright }}
        &nbsp;<a
          href="https://beian.miit.gov.cn/"
          target="_blank"
          style="color: #999; font-size: 14px"
          >ICP证：{{ website.icpURL }}</a
        >

        <a
          target="_blank"
          href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=44011202001838"
          style="
            display: inline-block;
            text-decoration: none;
            height: 20px;
            line-height: 20px;
            vertical-align: middle;
            margin-left: 12px;
          "
        >
          <img
            src="../../../public/img/PublicSecurity.png"
            style="float: left; width: 16px; height: 16px; vertical-align: middle;"
          />
          <p
            style="
              float: left;
              height: 20px;
              line-height: 20px;
              margin: 0px 0px 0px 5px;
              color: #939393;
            "
          >
            粤公网安备 44011202001838号
          </p>
        </a>
        &nbsp;{{ website.companyName }}
      </div>
    </div>
  </div>
</template>
<script>
import { fetchList } from "@/api/admin/tenant";
import userLogin from "./userlogin";
import codeLogin from "./codelogin";
import thirdLogin from "./thirdlogin";
import { mapGetters } from "vuex";
import { getStore, setStore } from "@/util/store";
import topColor from "@/page/index/top/top-color";
import reset from "./reset";

export default {
  name: "Login",
  components: {
    userLogin,
    codeLogin,
    thirdLogin,
    topColor,
    reset,
  },
  data() {
    return {
      tenantList: [],
      active: "",
      activeName: "user",
      socialForm: {},
    };
  },
  watch: {
    $route: {
      handler() {
        const params = this.$route.query;
        if (this.validatenull(params.state) && this.validatenull(params.code))
          return;

        this.socialForm.state = params.state;
        this.socialForm.code = params.code;

        const loading = this.$loading({
          lock: true,
          text: `登录中,请稍后。。。`,
          spinner: "el-icon-loading",
        });
        this.$store
          .dispatch("LoginBySocial", this.socialForm)
          .then(() => {
            loading.close();
            this.$router.push({ path: this.tagWel.value });
          })
          .catch(() => {
            loading.close();
          });
      },
      immediate: true,
    },
  },
  created() {
    this.watermark();
    this.getTenantList();
    this.active = getStore({ name: "tenantId" });
    if (this.$route.query.hasOwnProperty("tenantId") == false) {
      //hasOwnProperty()检测对象是否有某个属性,不能检测原型链上的属性
      const loading = this.$loading({
        lock: true,
        text: "您输入的地址无效,请输入完整地址",
        spinner: "el-icon-warning-outline",
        background: "rgba(255, 255, 255, 1)",
        customClass: "maskLoading",
      });
    }
    console.log(JSON.stringify(this.$route.query));
  },
  mounted() {},
  computed: {
    ...mapGetters(["website", "tagWel"]),
  },
  methods: {
    handleCommand(command) {
      setStore({ name: "tenantId", content: command });
    },
    getTenantList() {
      fetchList().then((response) => {
        this.tenantList = response.data.data;
      });
    },
    watermark() {
      const text = "";
      const canvas = document.createElement("canvas");
      canvas.width = "500";
      canvas.height = "200";
      const ctx = canvas.getContext("2d");
      ctx.clearRect(0, 0, 200, 200); // 绘制之前画布清除
      ctx.font = "30px 黑体";
      ctx.rotate((-20 * Math.PI) / 180); // 为了实现水印倾斜效果,旋转画布坐标系
      ctx.fillStyle = "rgba(100,100,100,0.15)"; // 画笔颜色
      ctx.fillText(text, -20, 200); // 书写的内容及位置
      ctx.rotate("20*Math.PI/180"); // 坐标系还原,如果后续没有其他操作,这一步可以省略
      // 将canvas的内容转换为base64编码
      const data = canvas.toDataURL("image/png", 1); // 1表示质量(无损压缩)

      window.onload = () => {
        const background = "url(" + data + ") repeat";
        var watermark = document.createElement("div");
        watermark.style.width = "100%";
        watermark.style.height = "100%";
        watermark.style.position = "fixed";
        watermark.style.left = "0";
        watermark.style.top = "0";
        watermark.style.pointerEvents = "none";
        watermark.style.background = background;
        watermark.style.zIndex = "9999";
        document.body.append(watermark);
      };
    },
  },
};
</script>

<style lang="scss">
@import "@/styles/login.scss";
.maskLoading .el-loading-spinner i {
  font-size: 65px;
  color: #000;
}
.maskLoading .el-loading-spinner .el-loading-text {
  font-size: 20px;
  font-weight: bold;
  color: #000;
}
.maskLoading .el-loading-mask.is-fullscreen .el-loading-spinner {
  margin-top: -50px;
}
</style>